export default {
    namespace: "cinames",
    state: {
        list: []
    },
    reducers: {
        setList(preStates: any, action: any) {
            return {
                ...preStates,
                list: action.payload
            }
        },
        removeList(preStates: any, action: any) {
            return {
                ...preStates,
                list: []
            }
        }


    },
    effects: {
        *getList(action: any, obj: any) {
            console.log("getList", action)
            console.log("getList", obj)
            const cityId = action.payload.cityId
            var res = yield obj.call(getListForCinames, cityId);
            console.log("call", res.data.cinemas)
            yield obj.put(
                {
                    type: "setList",
                    payload: res.data.cinemas
                }
            )
        }

    }
}

async function getListForCinames(cityId: any) {
    var res = await fetch(`https://m.maizuo.com/gateway?cityId=${cityId}&ticketFlag=1&k=2200632`,
        {
            headers: {
                'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.2.1","e":"16722220591298527527370753"}',
                'X-Host': 'mall.film-ticket.cinema.list'
            }
        }).then(res => res.json());
    return res;
}

